package ch.fusun.baron.coatofarms.ui.background;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import ch.fusun.baron.coatofarms.ui.COAColor;

/**
 * Vertically divided background
 */
public class VerticallyDividedBackground implements COABackground {

	private COAColor bottom;
	private COAColor top;

	/**
	 * Kryo
	 */
	public VerticallyDividedBackground() {
	}

	/**
	 * @param colorTop
	 * @param colorBottom
	 */
	public VerticallyDividedBackground(COAColor colorTop, COAColor colorBottom) {
		this.top = colorTop;
		this.bottom = colorBottom;
	}

	@Override
	public void drawBackground(GC gc, int x, int y, int width, int height) {
		short[] rgbT = top.getColorRGB();
		short[] rgbB = bottom.getColorRGB();

		int left = x - width / 2;
		int right = x + width / 2;
		int bottom = y - height / 2;
		int top = y + height / 2;

		gc.setBackground(new Color(gc.getDevice(), rgbT[0], rgbT[1], rgbT[2]));
		gc.fillRectangle(left, bottom, x, top);
		gc.setBackground(new Color(gc.getDevice(), rgbB[0], rgbB[1], rgbB[2]));
		gc.fillRectangle(x, bottom, right, top);
	}

	@Override
	public String uniqueCode() {
		return "VerticallyDividedBackground" + bottom + top;
	}
}
